package ch.exm.storm.conditions;

import ch.exm.storm.query.relational.RelationalQuery;

public abstract class TwoArgumentsCondition extends AbstractSimpleCondition {

	protected TwoArgumentsCondition(Object first, Object second) {
		arguments = new Object[] { first, second };
	}

	@Override
	public boolean evaluateRelationalCondition(RelationalQuery query, boolean inverse) {
		whereCondition = new StringBuilder(); 
		if (!isRelationalArgument(query, arguments[0])) return false;
		whereCondition.append(inverse ? getInverseConditionKeyword() : getConditionKeyword());
		if (!isRelationalArgument(query, arguments[1])) return false;
		return true;
	}
	
	public boolean matches(Object object) {
		return matches(evaluteArgumentOn(arguments[0], object), evaluteArgumentOn(arguments[1], object));
	}
	
	protected abstract boolean matches(Object firstValue, Object secondValue);
	
	@Override
	public String toString() {
		return argumentToString(arguments[0]) + getConditionKeyword() + argumentToString(arguments[1]);
	}
}
